﻿using System;
using System.Collections.Generic;

namespace MyLib.Data {
	/// <summary>
	/// Table of user.
	/// </summary>
	[System.ComponentModel.DesignerCategory("Code")]
	public class UserTable : System.Data.DataTable, System.Collections.Generic.IList<UserRow> {
		/// <summary>
		/// 
		/// </summary>
		public const int ColumnUserId = 0;

		/// <summary>
		/// 
		/// </summary>
		public const int ColumnUserName = 1;

		/// <summary>
		/// 
		/// </summary>
		public const int ColumnRealName = 2;

		/// <summary>
		/// 
		/// </summary>
		public const int ColumnStatus = 3;

		/// <summary>
		/// 
		/// </summary>
		public const int ColumnSeq = 4;

		/// <summary>
		/// 
		/// </summary>
		public const int ColumnGroupId = 5;

		/// <summary>
		/// 
		/// </summary>
		public const int ColumnRoles = 6;

		/// <summary>
		/// 
		/// </summary>
		public const int ColumnRoleNames = 7;

		/// <summary>
		/// Create a new instance of UserTable.
		/// </summary>
		protected override System.Data.DataTable CreateInstance() {
			return new UserTable();
		}

		/// <summary>
		/// Create as new instance of UserRow.
		/// </summary>
		/// <param name="builder">Builder for data row.</param>
		protected override System.Data.DataRow NewRowFromBuilder(System.Data.DataRowBuilder builder) {
			return new UserRow(builder);
		}

		/// <summary>
		/// Count of rows.
		/// </summary>
		public int Count {
			get {
				return base.Rows.Count;
			}
		}

		/// <summary>
		/// Get row.
		/// </summary>
		/// <param name="index">Index of row.</param>
		public UserRow this[int index] {
			get {
				return (UserRow)(base.Rows[index]);
			}
			set {
				throw new System.NotImplementedException();
			}
		}

		/// <summary>
		/// Add a row.
		/// </summary>
		/// <param name="row" >Row which will be added.</param>
		public void AddRow(UserRow row) {
			base.Rows.Add(row);
		}

		/// <summary>
		/// Remove a row.
		/// </summary>
		/// <param name="row" >Row which will be removed.</param>
		public void RemoveRow(UserRow row) {
			base.Rows.Remove(row);
		}

		/// <summary>
		/// Add a new row with default values.
		/// </summary>
		public UserRow AddNewRow() {
			var row = base.NewRow() as UserRow;

			System.Diagnostics.Debug.Assert(row != null);

			base.Rows.Add(row);

			return row;
		}

		/// <summary>
		/// Type of data row.
		/// </summary>
		protected override System.Type GetRowType() {
			return typeof(UserRow);
		}

		#region Members of System.Collections.Generic.IEnumerable<UserRow>.

		/// <summary>
		/// 
		/// </summary>
		/// <param name="item"></param>
		/// <returns></returns>
		public int IndexOf(UserRow item) {
			return base.Rows.IndexOf(item);
		}

		/// <summary>
		///
		/// </summary>
		/// <param name="index" ></param>
		/// <param name="item" ></param>
		public void Insert(int index, UserRow item) {
			base.Rows.InsertAt(item, index);
		}

		/// <summary>
		///
		/// </summary>
		/// <param name="index"></param>
		public void RemoveAt(int index) {
			base.Rows.RemoveAt(index);
		}

		/// <summary>
		///
		/// </summary>
		/// <param name="item" ></param>
		public void Add(UserRow item) {
			base.Rows.Add(item);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="item" ></param>
		/// <returns></returns>
		bool System.Collections.Generic.ICollection<UserRow>.Contains(UserRow item) {
			throw new System.NotImplementedException();
		}

		/// <summary>
		///
		/// </summary>
		/// <param name="keys" ></param>
		/// <returns></returns>
		public bool ContainsKey(params object[] keys) {
			System.Diagnostics.Debug.Assert(keys != null);
			System.Diagnostics.Debug.Assert(keys.Length != 0);

			return base.Rows.Contains(keys);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="array" ></param>
		/// <param name="arrayIndex" ></param>
		public void CopyTo(UserRow[] array, int arrayIndex) {
			base.Rows.CopyTo(array, arrayIndex);
		}

		/// <summary>
		/// 
		/// </summary>
		public bool IsReadOnly {
			get {
				return false;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="item" ></param>
		/// <returns></returns>
		public bool Remove(UserRow item) {
			base.Rows.Remove(item);
			return true;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns ></returns>
		public IEnumerator<UserRow> GetEnumerator() {
			var iter = base.Rows.GetEnumerator();
			while (iter.MoveNext()) {
				yield return iter.Current as UserRow;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns ></returns>
		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
			return base.Rows.GetEnumerator();
		}

		#endregion

		/// <summary>
		/// Initialize data table.
		/// </summary>
		public UserTable() {
			this.TableName = "UserTable";
			this.BeginInit();
			var column0 = new System.Data.DataColumn("userId", typeof(string), null, System.Data.MappingType.Attribute);
			column0.DefaultValue = "";
			column0.Unique = true;
			base.Columns.Add(column0);
			var column1 = new System.Data.DataColumn("userName", typeof(string), null, System.Data.MappingType.Attribute);
			column1.DefaultValue = "";
			column1.Unique = true;
			base.Columns.Add(column1);
			var column2 = new System.Data.DataColumn("realName", typeof(string), null, System.Data.MappingType.Attribute);
			base.Columns.Add(column2);
			var column3 = new System.Data.DataColumn("status", typeof(int), null, System.Data.MappingType.Attribute);
			column3.DefaultValue = 1;
			base.Columns.Add(column3);
			var column4 = new System.Data.DataColumn("seq", typeof(int), null, System.Data.MappingType.Attribute);
			base.Columns.Add(column4);
			var column5 = new System.Data.DataColumn("grpId", typeof(string), null, System.Data.MappingType.Attribute);
			column5.DefaultValue = "";
			base.Columns.Add(column5);
			var column6 = new System.Data.DataColumn("roles", typeof(string), null, System.Data.MappingType.Attribute);
			column6.DefaultValue = "";
			base.Columns.Add(column6);
			var column7 = new System.Data.DataColumn("roleNames", typeof(string), null, System.Data.MappingType.Attribute);
			column7.DefaultValue = "";
			base.Columns.Add(column7);
			base.PrimaryKey = new System.Data.DataColumn[] 
            { 
                column0 
            };
			this.EndInit();
		}
	} // end of UserTable.

	/// <summary>
	/// UserRow.
	/// </summary>
	[System.ComponentModel.DesignerCategory("Code")]
	public class UserRow : System.Data.DataRow {
		/// <summary>
		/// Initialize data row.
		/// </summary>
		public UserRow(System.Data.DataRowBuilder builder)
			: base(builder) {
		}

		/// <summary>
		/// 
		/// </summary>
		public string UserId {
			get {
				var col = base.Table.Columns[UserTable.ColumnUserId];

				if (base.IsNull(col)) {
					throw new System.NullReferenceException("Value of UserTable[\"userId\"] is null!");
				} else {
					return (string)(base[col]);
				}
			}
			set {
				var col = base.Table.Columns[UserTable.ColumnUserId];

				base[col] = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public void SetUserIdNull() {
			var col = base.Table.Columns[UserTable.ColumnUserId];

			base[col] = System.Convert.DBNull;
		}

		/// <summary>
		/// 
		/// </summary>
		public bool IsUserIdNull {
			get {
				var col = base.Table.Columns[UserTable.ColumnUserId];

				return base.IsNull(col);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string UserName {
			get {
				var col = base.Table.Columns[UserTable.ColumnUserName];

				if (base.IsNull(col)) {
					throw new System.NullReferenceException("Value of UserTable[\"userName\"] is null!");
				} else {
					return (string)(base[col]);
				}
			}
			set {
				var col = base.Table.Columns[UserTable.ColumnUserName];

				base[col] = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public void SetUserNameNull() {
			var col = base.Table.Columns[UserTable.ColumnUserName];

			base[col] = System.Convert.DBNull;
		}

		/// <summary>
		/// 
		/// </summary>
		public bool IsUserNameNull {
			get {
				var col = base.Table.Columns[UserTable.ColumnUserName];

				return base.IsNull(col);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string RealName {
			get {
				var col = base.Table.Columns[UserTable.ColumnRealName];

				if (base.IsNull(col)) {
					throw new System.NullReferenceException("Value of UserTable[\"realName\"] is null!");
				} else {
					return (string)(base[col]);
				}
			}
			set {
				var col = base.Table.Columns[UserTable.ColumnRealName];

				base[col] = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public void SetRealNameNull() {
			var col = base.Table.Columns[UserTable.ColumnRealName];

			base[col] = System.Convert.DBNull;
		}

		/// <summary>
		/// 
		/// </summary>
		public bool IsRealNameNull {
			get {
				var col = base.Table.Columns[UserTable.ColumnRealName];

				return base.IsNull(col);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public int Status {
			get {
				var col = base.Table.Columns[UserTable.ColumnStatus];

				if (base.IsNull(col)) {
					throw new System.NullReferenceException("Value of UserTable[\"status\"] is null!");
				} else {
					return (int)(base[col]);
				}
			}
			set {
				var col = base.Table.Columns[UserTable.ColumnStatus];

				base[col] = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public void SetStatusNull() {
			var col = base.Table.Columns[UserTable.ColumnStatus];

			base[col] = System.Convert.DBNull;
		}

		/// <summary>
		/// 
		/// </summary>
		public bool IsStatusNull {
			get {
				var col = base.Table.Columns[UserTable.ColumnStatus];

				return base.IsNull(col);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public int Seq {
			get {
				var col = base.Table.Columns[UserTable.ColumnSeq];

				if (base.IsNull(col)) {
					throw new System.NullReferenceException("Value of UserTable[\"seq\"] is null!");
				} else {
					return (int)(base[col]);
				}
			}
			set {
				var col = base.Table.Columns[UserTable.ColumnSeq];

				base[col] = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public void SetSeqNull() {
			var col = base.Table.Columns[UserTable.ColumnSeq];

			base[col] = System.Convert.DBNull;
		}

		/// <summary>
		/// 
		/// </summary>
		public bool IsSeqNull {
			get {
				var col = base.Table.Columns[UserTable.ColumnSeq];

				return base.IsNull(col);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string GroupId {
			get {
				var col = base.Table.Columns[UserTable.ColumnGroupId];

				if (base.IsNull(col)) {
					throw new System.NullReferenceException("Value of UserTable[\"grpId\"] is null!");
				} else {
					return (string)(base[col]);
				}
			}
			set {
				var col = base.Table.Columns[UserTable.ColumnGroupId];

				base[col] = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public void SetGroupIdNull() {
			var col = base.Table.Columns[UserTable.ColumnGroupId];

			base[col] = System.Convert.DBNull;
		}

		/// <summary>
		/// 
		/// </summary>
		public bool IsGroupIdNull {
			get {
				var col = base.Table.Columns[UserTable.ColumnGroupId];

				return base.IsNull(col);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string Roles {
			get {
				var col = base.Table.Columns[UserTable.ColumnRoles];

				if (base.IsNull(col)) {
					throw new System.NullReferenceException("Value of UserTable[\"roles\"] is null!");
				} else {
					return (string)(base[col]);
				}
			}
			set {
				var col = base.Table.Columns[UserTable.ColumnRoles];

				base[col] = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public void SetRolesNull() {
			var col = base.Table.Columns[UserTable.ColumnRoles];

			base[col] = System.Convert.DBNull;
		}

		/// <summary>
		/// 
		/// </summary>
		public bool IsRolesNull {
			get {
				var col = base.Table.Columns[UserTable.ColumnRoles];

				return base.IsNull(col);
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string RoleNames {
			get {
				var col = base.Table.Columns[UserTable.ColumnRoleNames];

				if (base.IsNull(col)) {
					throw new System.NullReferenceException("Value of UserTable[\"roleNames\"] is null!");
				} else {
					return (string)(base[col]);
				}
			}
			set {
				var col = base.Table.Columns[UserTable.ColumnRoleNames];

				base[col] = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public void SetRoleNamesNull() {
			var col = base.Table.Columns[UserTable.ColumnRoleNames];

			base[col] = System.Convert.DBNull;
		}

		/// <summary>
		/// 
		/// </summary>
		public bool IsRoleNamesNull {
			get {
				var col = base.Table.Columns[UserTable.ColumnRoleNames];

				return base.IsNull(col);
			}
		}
	} // end of UserRow.
}
